package com.aca.action;

import com.aca.entity.Admin;
import com.aca.service.AdminService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.util.Map;

public class AdminAction extends ActionSupport {
    private Admin admin;
    private AdminService adminService;

    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    public AdminService getAdminService() {
        return adminService;
    }

    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

    @Override
    public String execute(){
        return SUCCESS;
    }

    //未完善定义异常
    public String login() throws Exception{
        Admin tmp = adminService.checkAdmin(admin.getUsername(),admin.getPwd());
        if (tmp!=null){
            Map session = ActionContext.getContext().getSession();
            session.put("admin",admin);
            //置空
            this.admin = null;
            return SUCCESS;
        }else {
            return ERROR;
        }
    }
}
